package com.xl.xlserver.utils;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;

public class ScoketUntils {
    public static String readMsg(Object msg){
        ByteBuf buf = (ByteBuf)msg;
        byte[] req = new byte[buf.readableBytes()];
        buf.readBytes(req);
        String dadaJson = new String(req, StandardCharsets.UTF_8);
        return dadaJson;
    }
  public static  String CliectAddress(ChannelHandlerContext ctx){
      InetSocketAddress ipSocket = (InetSocketAddress)ctx.channel().remoteAddress();
      String clientIp = ipSocket.getAddress().getHostAddress();
      int port = ipSocket.getPort();
      return  clientIp+":"+port;
  }

}
